package game.nm;

import game.module.Exploration.iMapScreen;
import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.engine.camera.hud.controls.AnalogOnScreenControl;
import org.anddev.andengine.engine.options.EngineOptions;
import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.opengl.texture.Texture;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.opengl.texture.region.TextureRegionFactory;
import org.anddev.andengine.ui.activity.BaseGameActivity;
import org.anddev.andengine.extension.physics.box2d.*;

public class fuckme extends BaseGameActivity {
	//varblock-----------------------------------
	private int width, height;
	private int cSensitivity;
	private Camera viewport;
	private AnalogOnScreenControl cstick;
	private Sprite PlayerS;
	public static final float gravY = 30;
	public static final float gravx = 0;
	//===========================================
	//images-------------------------------------
	private Texture playerT;
	private TextureRegion playerTR;
	private Texture cBaseT;
	private Texture cKnobT;
	private TextureRegion cBaseTR;
	private TextureRegion cKnobTR;
	//===========================================
	//physics------------------------------------
	private PhysicsWorld pWorld;
	//===========================================
	public Engine onLoadEngine(){
		width = 720;
		height = 480;
		cSensitivity = 100;
		viewport = new Camera(0, 0, width, height);
		//load up the engine
		EngineOptions eopt = new EngineOptions(true,
			EngineOptions.ScreenOrientation.LANDSCAPE,
			new RatioResolutionPolicy(width, height), viewport);
		eopt.getTouchOptions().setRunOnUpdateThread(true);
		return new Engine(eopt);
	}
	public void onLoadResources(){
		//load up faceman
		playerT = new Texture(32, 32, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		playerTR = TextureRegionFactory.createFromAsset(playerT, this, "gfx/face_box.png", 0, 0);
		this.mEngine.getTextureManager().loadTexture(playerT);
		//load up the cstick
		cBaseT = new Texture(128, 128, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		cBaseTR = TextureRegionFactory.createFromAsset(cBaseT, this, "gfx/cBase.png", 0, 0);
		this.mEngine.getTextureManager().loadTexture(cBaseT);
		cKnobT = new Texture(64, 64, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		cKnobTR = TextureRegionFactory.createFromAsset(cKnobT, this, "gfx/cKnob.png", 0, 0);
		this.mEngine.getTextureManager().loadTexture(cKnobT);
	}
	public Scene onLoadScene(){
		iMapScreen scrn = new iMapScreen("hithere");
		return scrn.LoadScene(this, viewport);
		/*
		//final list of map sprites
		final Shape center = new Rectangle(20, 300, width - 40, 10);
		center.setColor(0, 0, 0);
		PlayerS = new Sprite(width/2, height/2, playerTR);
		//--------------------------
		//physics handler-----------
		pWorld = new PhysicsWorld(new Vector2(0, SensorManager.GRAVITY_EARTH), false);
		//--------------------------
		//set up the physics world--
		final FixtureDef df = PhysicsFactory.createFixtureDef(0, 0.5f, 0.5f);
		PhysicsFactory.createBoxBody(pWorld, center, BodyType.StaticBody, df);
		//--------------------------
		//add the pc----------------
		final FixtureDef pcdf = PhysicsFactory.createFixtureDef(1, 0.5f, 0.5f);
		final Body pcB = PhysicsFactory.createBoxBody(pWorld, PlayerS, BodyType.DynamicBody, pcdf);
		pWorld.registerPhysicsConnector(new PhysicsConnector(PlayerS, pcB, true, true));
		//--------------------------
		Scene scn = new Scene(2);
		scn.setBackground(new ColorBackground(0, 225, 0));

		cstick = new AnalogOnScreenControl(20, 20, viewport, cBaseTR, cKnobTR, 0.3f, 200, new IAnalogOnScreenControlListener() {
			@Override
			public void onControlChange(final BaseOnScreenControl pBaseOnScreenControl, final float pValueX, final float pValueY){
				pcB.setLinearVelocity(pValueX * 50, pValueY * 50);
			}
			@Override
			public void onControlClick(final AnalogOnScreenControl pAnalogOnScreenControl){}
		});


		scn.getFirstChild().attachChild(center);
		scn.getFirstChild().attachChild(PlayerS);
		scn.setChildScene(cstick);
		scn.registerUpdateHandler(pWorld);
		return scn;*/
	}
	public void onLoadComplete(){
	}
}
